package com.yvan.leto.server.service;

import com.fasterxml.jackson.databind.JsonNode;
import com.yvan.YvanUtil;
import lombok.Cleanup;
import lombok.SneakyThrows;
import lombok.val;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.List;

public interface IParser {
    String process(ParserContext context);


    @SneakyThrows
    static JsonNode mergeResourceContentToJsonNode(List<File> resourceList) {
        //合并所有 Resource
        JsonNode jsonNode = null;
        for (val f : resourceList) {
            @Cleanup InputStream is = new FileInputStream(f);
            if (jsonNode == null) {
                jsonNode = YvanUtil.readYamlTree(is);
            } else {
                YvanUtil.merge(jsonNode, YvanUtil.readYamlTree(is));
            }
        }
        return jsonNode;
    }
}
